import { INotifier, IFacade } from "../../Interfaces";
import { Facade } from "../facade/Facade";

export class Notifier implements INotifier {
  
  multitonKey: string = null;

  sendNotification(name: string, body?: any, type?: string): void {
    if (this.facade()) {
      this.facade().sendNotification(name, body, type);
  
    }
  }
  
  initializeNotifier(key: string): void {
    this.multitonKey = key;
  }

  facade(): IFacade {
    
    if (this.multitonKey === null) 
      throw Error(Notifier.MULTITON_MSG);
    return Facade.getInstance(this.multitonKey);
  }

  static MULTITON_MSG: string = "multitonKey for this Notifier not yet initialized";
}